<?php
/*
 * Author: Quan Van Sinh
 * Email: sinhquan@vietnambiz.com
 */
checkLoginHeader();
checkPermission();
//categoryAction();
$question = new question();
$question->action();
?>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/header.php'; ?>
<script type="text/javascript">
    checked=false;
    function checkedAll (formId) {
        var aa= document.getElementById(formId);
        if (checked == false)        {
            checked = true;
        }else{
            checked = false;
        }
        for (var i =0; i < aa.elements.length; i++){
            aa.elements[i].checked = checked;
        }
    }
	
    $(document).ready(function(){
        setTimeout("closeResultMessages()",5000);
    });

    function closeResultMessages(){
        if ( $("#rsMessages").length > 0 ) {
            document.getElementById('rsMessages').style.display = 'none';
        }
    }

    function actionMultil(action){
        if(action=='delete'){
            if (confirm("Do you want to delete these question?")){
                document.getElementById('formView').submit();
            }else{
                document.getElementById('action').value = '';
            }
        }else{
            document.getElementById('formView').submit();
        }
    }
</script>

<div id="wrapper">
    <div id="content" style="width: 98%;">
        <div id="rightnow">
            <h3 class="reallynow">
                <span>Search</span>
                <br />
            </h3>
            <div class="youhave">
                <form method="get" action="/<?php echo $config ['admin_section']; ?>/question" id="form" name="form" enctype="multipart/form-data" style="padding-top: 10px">

                    <label for="searchKeyword">Keyword : </label>
                    <input style="width: 200px" type="text"  name="keyword" value="<?php echo htmlentities($_GET['keyword'], ENT_QUOTES, "UTF-8"); ?>"/>
                    <input type="submit" value="Search"/>
                    
                </form>
            </div>
        </div><br/>
        <?php
        $rsPostArticle = $question->getAllQuestion($config ['total_article_on_admin']);
        ?>
        <div id="rightnow">
            <h3 class="reallynow">
                <span>List questions</span>
                <span style="float: right;">
                    <form name="frmShowByStatus" action="" method="post" style="padding: 0; margin: 0;">
                        <select onchange="document.frmShowByStatus.submit();" style="width:150px; padding:0px;" name="status">
                            <option value="all">View by status ( all )</option>
                            <option <?php echo $_SESSION['questionStatusFilter']=='yes'?'selected="selected"':'';?> value="yes">Yes only</option>
                            <option <?php echo $_SESSION['questionStatusFilter']=='no'?'selected="selected"':'';?> value="no">No only</option>
                        </select>
                    </form>
                </span>
                <br />
            </h3>
            <div class="youhave">
                <form method="post" action="" id="formView">
                    <div id="rsMessages" style="text-align: center; color: red; font-weight: bolder"><?
if (isset($_SESSION['rsMessages'])) {
    echo $_SESSION['rsMessages'];
    $_SESSION['rsMessages'] = '';
}
?></div>
                    <table width="100%">
                        
                        <tbody>
                            <tr>
                                <td width="40px"><font title="Total not active">NA</font>|<font title="Total actived">A</font></td>
                                <td width="140"><b>Fullname</b></td>
                                <td><b>Question</b></td>
                                <td style="text-align:center;" width="60px"><b>status</b></td>
                                <td width="120" style="text-align:center; padding:5px;"><b>Date post</b></td>
                                <td width="40px" style="text-align:center;"><b>Actions</b></td>
                            </tr>
                            <?php
                            $i = 0;
                            while ($rs = $db->fetch_array($rsPostArticle['rs'])) {
                                $i++;
                                $countAnswer = $question->countAnswerInQuestion($rs['id']);
                                ?>
                                <tr class="listItem">
                                    <td class="a-center" style="height:30px;"><?php echo $countAnswer['totalNotActive'].'|'.$countAnswer['totalActive']; ?></td>
                                    <td style="padding:8px 5px;">
                                        <?php echo $rs['fullname']; ?>
                                    </td>
                                    <td style="padding:8px 5px;">
                                        <a href="/<?php echo $config ['admin_section']; ?>/detail_question?id=<?php echo $rs['id']; ?>&keepThis=true&TB_iframe=true&height=400&width=500" class="thickbox">
                                            <img height="16" width="16" title="View question" src="<?php echo $config ['admin_images_url']; ?>/icons/page_white_text_width.png" alt="view"/>
                                        </a>
                                        <a href="/<?php echo $config ['admin_section']; ?>/question/<?php echo $config['page']; ?>?action=viewQuestion&id=<?php echo $rs['id']; ?>" title="Edit question & view answers">
                                        <?php
                                        if($countAnswer['totalNotActive']>0){
                                            echo '<b>'.cutString($rs['question'], 72).'</b>';
                                        }else{
                                            echo cutString($rs['question'], 72);
                                        }
                                        ?>
                                        </a>
                                        
                                    </td>
                                    <td class="a-center">
                                        <?php
                                        echo $rs['active'] ? "Yes" : "No";
                                        ?>
                                    </td>
                                    <td align="center" style="font-size:10px;">
                                        <?php echo date("d/m/Y H:i:s", strtotime($rs['create_date'])); ?>
                                    </td>
                                    <td valign="middle" class="a-center">
                                        <input type="checkbox" id="multiId" name="multiId[]" value="<?php echo $rs['id']; ?>">
                                    </td>
                                </tr>

                                <?php
                            }
                            ?>


                        </tbody>
                    </table>
                    <div style="text-align: right">
                        <select id="action" name="action" onchange="actionMultil(this.value);" style="width:120px; padding:0px;">
                            <option value="">Select action</option>
                            <option value="delete">Delete</option>
                            <option value="active_yes">Set active yes</option>
                            <option value="active_no">Set active no</option>
                            <option value="hot_yes">Set hot yes</option>
                            <option value="hot_no">Set hot no</option>
                            <option value="top_yes">Set top yes</option>
                            <option value="top_no">Set top no</option>
                        </select>
                        <input type="hidden" value="delete" name="hDel" id="hDel" />
                        <b>Select all/Unselect all:</b>
                        <input type="checkbox" name="checkall" onclick="javascript: checkedAll('formView');">
                    </div>
                </form>
            </div>
            <div class="linepagination">
                <div class="pagination">
                    <ul>
                        <?php
                        echo pagingAdmin($config ['page'], $rsPostArticle['totalPage']);
                        ?>
                    </ul>
                </div>

            </div>
        </div>

    </div>


</div>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/footer.php'; ?>